package com.lzxxkjxx.bigwork.Service;

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.util.Log;

public class MainService extends Service {


    private final String TAG ="MainService";
    private boolean mServiceRunning = false;
    private int mSecond = 0;

    public IBinder onBind(Intent intent) {
        Log.i(TAG,"onBind方法被调用!");
        return null;
    }
    @Override
    public void onCreate(){
        Log.i(TAG,"onCreate方法被调用!");
        super.onCreate();
    }

    @Override
    public int onStartCommand(Intent intent,int flags,int startId) {
        Log.i(TAG,"onStartCommand方法被调用！");
        new Thread() {
            @Override
            public void run() {
                mServiceRunning =true;
                while (mServiceRunning) {
                    Log.i(TAG,"新线程已经运行了"+mSecond +"秒");
                    try{
                        sleep(1000);
                        mSecond++;
                    }catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        }.start();
        return super.onStartCommand(intent,flags,startId);
    }

    @Override
    public void onDestroy(){
        Log.i(TAG,"onDestroy方法被调用!");
        mServiceRunning=false;
        super.onDestroy();
    }
}


